package com.easylinkin.linkappapi.openapi.controller;

import java.io.UnsupportedEncodingException;
import javax.annotation.Resource;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.easylinkin.linkappapi.openapi.service.impl.OpenApiEasyvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value="openApi-DataV控制器",tags={"dataV调用API接口"})
@RestController
@RequestMapping({"/openAPI", "openapi"})
public class OpenApiEasyvController {
	
	@Resource
	private OpenApiEasyvService openApiService;

	/**
	 * 查询可视化数据配置
	 * @param token
	 * @return
	 * @throws UnsupportedEncodingException
	 */
  @ApiOperation("查询可视化数据配置")
  @PostMapping("get3dData")
  public JSONObject get3dData(String token) throws UnsupportedEncodingException {
      JSONObject parseObject = openApiService.get3dData(token);
      return parseObject;
  }
  /**
   * 更新可视化数据
   * @param data
   * @return
   * @throws UnsupportedEncodingException
   */
  @ApiOperation("更新可视化数据")
  @PostMapping("update3dData")
  public JSONObject update3dData(@RequestBody JSONObject data) throws UnsupportedEncodingException {
      JSONObject parseObject = openApiService.update3dData(data);
      return parseObject;
  }

  @ApiOperation("根据token获取LinkThings 3D可视化列表的")
  @PostMapping("get3dInstances")
  public JSONObject get3dInstances(String token) throws UnsupportedEncodingException {
      JSONObject parseObject = openApiService.get3dInstances(token);
      return parseObject;
  }

  @ApiOperation("获取LinkThings 3D可视化列表的")
  @RequestMapping(value = "get3dInstancesByProject", method = {RequestMethod.GET,RequestMethod.POST})
  public JSONObject get3dInstancesByProject() throws UnsupportedEncodingException {
      JSONObject parseObject = openApiService.get3dInstancesByProject();
      return parseObject;
  }

  @ApiOperation("获取LinkThings 2D可视化列表的")
  @RequestMapping(value = "getDatavInstancesByProject", method = {RequestMethod.GET,RequestMethod.POST})
  public JSONObject getDatavInstanceByProject(@RequestBody JSONObject jsonObject) throws UnsupportedEncodingException {
    JSONObject parseObject = openApiService.getDatavInstancesByProject(jsonObject);
    return parseObject;
  }
    
  /**
   * 获取3d可视化配置
   *
   * @param tenantId 租户ID
   * @param project 项目信息
   * @return
   */
  @ApiOperation("3d可视化模型列表")
  @PostMapping("ht3dResource/listPage")
  public JSONObject listPageTemplate(
      @RequestBody JSONObject restPage) throws UnsupportedEncodingException  {
    Assert.notNull(restPage, "RestPage不能为空");

    return openApiService.get3dModelList(restPage);
  }

  /**
   * 查询3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("获取3d可视化模型")
  @GetMapping("ht3dResource/{id}")
  public JSONObject get(@PathVariable("id") String id) throws UnsupportedEncodingException  {
    Assert.notNull(id, "ID不能为空");
    return openApiService.get3dModel(id);
  }

  /**
   * 新增3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("新增3d可视化模型")
  @PutMapping("ht3dResource")
  public JSONObject add(@RequestBody JSONObject data) throws UnsupportedEncodingException  {
    Assert.notNull(data, "数据不能为空");
    Assert.notNull(data.getString("name"), "名称不能为空");
    Assert.notNull(data.getJSONObject("data"), "data不能为空");

    return openApiService.add3dModel(data);
  }

  /**
   * 更新3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("更新3d可视化模型")
  @PostMapping("ht3dResource/update")
  public JSONObject update(@RequestBody JSONObject data) throws UnsupportedEncodingException  {
    Assert.notNull(data, "数据不能为空");
    Assert.notNull(data.getString("id"), "id不能为空");
    Assert.notNull(data.getString("name"), "名称不能为空");

    return openApiService.update3dModel(data);
  }

  /**
   * 更新3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("删除3d可视化模型")
  @DeleteMapping("ht3dResource/{id}")
  public JSONObject delete(@PathVariable("id") String id) throws UnsupportedEncodingException  {
    Assert.notNull(id, "ID不能为空");
    return openApiService.delete3dModel(id);
  }
    
  /**
   * 获取3d公共模型列表
   *
   * @return
   */
  @ApiOperation("3d可视化公共模型列表")
  @PostMapping("ht3dResource/publicModels")
  public JSONObject publicModels(
      @RequestBody JSONObject restPage) throws UnsupportedEncodingException  {
    Assert.notNull(restPage, "RestPage不能为空");

    return openApiService.publicModels(restPage);
  }
  /**
   * 获取3d图片资源列表
   *
   * @param tenantId 租户ID
   * @param project 项目信息
   * @return
   */
  @ApiOperation("3d可视化模型列表")
  @PostMapping("ht3dResource/img/listPage")
  public JSONObject listImgPageTemplate(
      @RequestBody JSONObject restPage) throws UnsupportedEncodingException  {
    Assert.notNull(restPage, "RestPage不能为空");

    return openApiService.get3dImgList(restPage);
  }
    
  /**
   * 更新3d图片资源
   *
   * @param data
   * @return
   */
  @ApiOperation("删除3d可视化模型")
  @DeleteMapping("ht3dResource/img/{id}")
  public JSONObject deleteImg(@PathVariable("id") String id) throws UnsupportedEncodingException  {
    Assert.notNull(id, "ID不能为空");
    return openApiService.delete3dImg(id);
  }
    
  /**
   * 新增3d图片资源
   *
   * @param data
   * @return
   */
  @ApiOperation("新增3d可视化模型")
  @PutMapping("ht3dResource/img")
  public JSONObject addImg(@RequestBody JSONObject data) throws UnsupportedEncodingException  {
    Assert.notNull(data, "数据不能为空");
    Assert.notNull(data.getString("name"), "名称不能为空");

    return openApiService.add3dImg(data);
  }
    
  @ApiOperation("3d可视化模型类别列表")
  @PostMapping("ht3d/category/listPage")
  public JSONObject categoryListPage(
      @RequestBody JSONObject restPage) throws UnsupportedEncodingException  {
    Assert.notNull(restPage, "RestPage不能为空");

    return openApiService.get3dModeCategorylList(restPage);
  }

  /**
   * 查询3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("获取3d可视化模型类别")
  @GetMapping("ht3d/category/{id}")
  public JSONObject categoryGet(@PathVariable("id") String id) throws UnsupportedEncodingException  {
    Assert.notNull(id, "ID不能为空");
    return openApiService.get3dModelCategory(id);
  }

  /**
   * 新增3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("新增3d可视化模型类别")
  @PutMapping("ht3d/category")
  public JSONObject categoryAdd(@RequestBody JSONObject data) throws UnsupportedEncodingException  {
    Assert.notNull(data, "数据不能为空");
    Assert.notNull(data.getString("name"), "名称不能为空");

    return openApiService.add3dModelCategory(data);
  }

  /**
   * 更新3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("更新3d可视化模型类别")
  @PostMapping("ht3d/category/update")
  public JSONObject categoryUpdate(@RequestBody JSONObject data) throws UnsupportedEncodingException  {
    Assert.notNull(data, "数据不能为空");
    Assert.notNull(data.getString("id"), "id不能为空");
    Assert.notNull(data.getString("name"), "名称不能为空");

    return openApiService.update3dModelCategory(data);
  }

  /**
   * 更新3d配置
   *
   * @param data
   * @return
   */
  @ApiOperation("删除3d可视化模型类别")
  @DeleteMapping("ht3d/category/{id}")
  public JSONObject categoryDelete(@PathVariable("id") String id) throws UnsupportedEncodingException  {
    Assert.notNull(id, "ID不能为空");
    return openApiService.delete3dModelCategory(id);
  }
}
